﻿using ReflectionStudio.Core.Events;
using System;
using System.Data;
using System.Windows;
using System.Windows.Data;
using System.ComponentModel;
namespace WPFExcelReport
{
    public partial class K8885
    {
        public K8885()
        {
            if (DesignerProperties.GetIsInDesignMode(this))
                return;
            SDSA = "8885";   
            InitializeComponent(); 
        }
        public override void Window_Loaded(object sender, RoutedEventArgs e)
        {
            if (DesignerProperties.GetIsInDesignMode(this))
                return;
            if (IsLoaded) return;
            base.Window_Loaded(sender, e);
            LOADALL();
            //NormalTask= Task.Factory.StartNew(() => LOADALL(), new CancellationTokenSource().Token, TaskCreationOptions.None, TaskScheduler.FromCurrentSynchronizationContext());
        }
        public override void LOADALL()
        {
            if (!IsLoaded)
                return;
            base.LOADALL();
            foreach (DataRow row in TBMain.Rows)
            {
                row["SDES"] = Helpers.Helper.Convert8859P1ToGB2312(row["SDES"].ToString().Trim());
                row["DES"] = Helpers.Helper.Convert8859P1ToGB2312(row["DES"].ToString().Trim());
            }
            bgWorker.RunWorkerAsync();
        }
        public override void bgWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            base.bgWorker_DoWork(sender, e);
            CHKGB03();
        }
        private void CHKGB03()
        {
            //现在的最大值
            string start = "1";//
            MV.or1 = MV.OracleDB.CreateCommand();
            MV.or1.CommandText = "SELECT MAX(GPPARTIE) AS GPPARTIE  FROM GPDAT WHERE GPMANDANT='" + app.Mandant + "'";
            SResult = MV.Connect2Proxy(MV.or1);
            foreach (DataRow row in SResult.Tables[0].Rows)
            {
                start = row["GPPARTIE"].ToString();
                TMV.RESETSEQ("8885", "  ", "GB03", start,10);
            } 
        }
    }
}
